//
//  DrawViewController.m
//  Leisure
//
//  Created by xalo on 16/6/28.
//  Copyright © 2016年 蓝鸥科技有限公司西安分公司. All rights reserved.
//

#import "DrawViewController.h"

@interface DrawViewController ()<menuViewControllerDelegate>
@property (nonatomic,strong)MenuViewController *menuVC;//接收菜单栏
@property (nonatomic,strong)UINavigationController *rightNVC;//右侧视图导航栏控制器

@end

@implementation DrawViewController


//自定义初始化方法，在初始化的时候，就直接给上左右控制器
- (instancetype)initWithMenuViewController:(MenuViewController *)menuVC RightViewController:(RightViewController *)rightVC{
    self = [super init];
    if (self) {
        self.menuVC = menuVC;
        self.menuVC.delegate = self;
        self.rightNVC = [[UINavigationController alloc]initWithRootViewController:rightVC];
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationController.navigationBar.translucent = NO;

    
    //添加子视图控制器
    [self addChildViewController:self.menuVC];
    [self addChildViewController:self.rightNVC];
    //添加子视图
    
    [self.view addSubview:self.menuVC.view];
    [self.view addSubview:self.rightNVC.view];
    
    
}

//实现协议方法，更换右视图
-(void)menuViewControllerDidClickCellWithVC:(RightViewController *)VC{
    
    [UIView animateWithDuration:0.2 animations:^{
        //替换之前先把旧的向右偏移
        self.rightNVC.view.frame = CGRectMake(kWidth, 0, kWidth, kHeight);
    } completion:^(BOOL finished) {
        //先移除旧的
        [self.rightNVC removeFromParentViewController];
        [self.rightNVC.view removeFromSuperview];
        //再添加新的
        self.rightNVC = [[UINavigationController alloc]initWithRootViewController:VC];
        [self addChildViewController:self.rightNVC];
        [self.view addSubview:self.rightNVC.view];
        self.rightNVC.view.frame = CGRectMake(kWidth, 0, kWidth, kHeight);
        // 把新的再偏移回来
        [UIView animateWithDuration:1 delay:0.2 options:UIViewAnimationOptionLayoutSubviews animations:^{
            self.rightNVC.view.frame = self.view.frame;
        } completion:^(BOOL finished) {
            
        }];
        

        
    }];
    
    
    
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
